<!--
 * @Author: zxc
 * @Date: 2020-07-15 08:54:24
 * @LastEditTime: 2020-07-15 10:04:52
 * @LastEditors: zxc
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo-reactive</title>
  <script src="./vue3-composition-api.js"></script>
</head>

<body>
  <div id="root"></div>
  <div id="btn">you should click it</div>
  <script>
    const root = document.getElementById('root');
    const btn = document.getElementById('btn');

    const obj = reactive({
      name: 'It is a reactive demo',
      num: 1
    });

    let double = computed(() => obj.num * 2);

    effect(() => {
      console.log('now,date is changed', obj.num)
      root.innerHTML = `<h1>${obj.name} now ,the raw num is ${obj.num},the new num is ${double.value}</h1>`
    });

    btn.addEventListener('click', () => {
      obj.num += 1
    });

  </script>
</body>

</html>